<template>
    <!-- 提示框   -->
    <Popup @cancel='cancel' @confirm='btnPhone' :isShow="isShow" title="请填写用户名和手机号">
        <div class="phoneTxt vux-1px-b"><input refs="inputs" v-model="phoneTxt_name" type="text" placeholder="请输入用户名"></div>
        <div class="phoneTxt vux-1px-b"><input maxlength="11" v-model="phoneTxt_phone" type="text" placeholder="请输入手机号"></div>
        <!-- <div class="phoneTxt vux-1px-b">
            <input type="text" v-model="regText" placeholder="请输入验证码">
            <button @click.stop="regPhone">测试</button>
        </div> -->
    </Popup>
</template>
<script>
import Popup from 'common/popup/popup';
import { bindUserInfoPhone,bindPhoneSendSms } from 'request';
import { isPhoneNum } from 'methods/common';
import { Toast } from 'mint-ui';
export default {
    name:'regPhone',//注册手机号码公共组件
    props:{
        isShow:{
            default:false
        }
    },
    data(){
        return {
            phoneTxt_phone: '', 
            phoneTxt_name: '',
            regText:'',
            resRegCode:'',
        }
    },
    methods:{
        btnPhone() {
            if (!isPhoneNum(this.phoneTxt_phone)) {
                Toast({ message: "手机号码有误，请重填",duration: 1000 });
                return false;
            }
            bindUserInfoPhone({ phone: this.phoneTxt_phone, name: this.phoneTxt_name }).then(res => {
                if (res.rspCode == "0000") {
                    Toast({ message: "绑定成功", position: "middle", duration: 2000 });
                    this.confirm();
                } else {
                    Toast({ message: '注册失败', position: "middle", duration: 2000 });
                }
            }).catch( error => {
                Toast({ message: "绑定失败请重新绑定", position: "middle", duration:2000 });
            });
        },
        //取消事件
        cancel(){
            this.$emit('cancel');
        },
        //确定事件
        confirm(){
            this.$emit('confirm');
        },
        regPhone(){
            if(!isPhoneNum(this.phoneTxt_phone)){
                Toast({ message: "请先输入正确的手机号", position: "middle", duration:2000 });
                return
            }
            bindPhoneSendSms({phone: this.phoneTxt_phone}).then(res=>{
                if(res.rspCode == '0000' && res.data.resultCode == '0000'){
                    res.resRegCode = res.data.verifyCode;
                }else{
                    
                }
            })
        }
    },
    components:{
        Popup,
    }
}
</script>
<style lang='less' scoped>
.phoneTxt{
    height:3.5rem;
    width:90%;
    margin:.5rem auto 0;
    box-sizing:border-box;
    & input{
        border:none;
        height:100%;
        width:100%;
        padding-left:1rem;
    }
}
</style>

